package com.xo.user.service.impl;

import com.xo.common.pojo.entity.SysUserEntity;
import com.xo.user.controller.LoginUser;
import com.xo.user.mapper.LoginMapper;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class UserDetailsServiceImpl implements UserDetailsService {

    @Resource
    private LoginMapper loginMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUserEntity sysUserEntity = loginMapper.selectSysUserByUsername(username);
        LoginUser loginUser = new LoginUser(sysUserEntity.getUsername(), sysUserEntity.getPassword(), new ArrayList<>(), sysUserEntity.getTenantId());
        return loginUser;
    }

}
